﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic.Web;
using LotteryVote.Logic;
using LotteryVote.Logic.Application;

namespace LotteryVote
{
    public partial class SheetManager : CompanyPage
    {
        BetFacade _betFacade;
        public BetFacade BlBet
        {
            get
            {
                if (_betFacade == null)
                    _betFacade = new BetFacade();
                return _betFacade;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lv_pager.InitPager();
            if (!IsPostBack)
                BindSheet();
        }

        void BindSheet()
        {
            int totalCount;
            rpt_sheet.DataSource = BlBet.GetTodayValidBetSheets(LotterySystem.Current.PageItemCount, lv_pager.CurrentPager, out totalCount);
            rpt_sheet.DataBind();
            lv_pager.BindPager(totalCount, LotterySystem.Current.PageItemCount);
        }

        protected void rpt_sheet_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "cancel")
            {
                Execute(() =>
                {
                    int sheetId = Convert.ToInt32(e.CommandArgument);
                    BlBet.CancelBetSheet(sheetId, CurrentUser);
                    BindSheet();
                    ShowMessage("Result", GetGlobalResourceObject("Resource", "Success").ToString());
                });
            }
        }
    }
}